var code;
		
function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}
function deldepartment(id){
	layer.confirm("确定删除此部门吗?",function(){
		  $.ajax({
				url : path+"/department/department_delete",
				cache : false,
				type : 'post',
				dataType : 'html',
				data : {
					"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
	        		if(message == "200"){
	                    layer.msg('操作成功!',{icon:1,time:1000},function(){
	                        window.location.reload();
	                    });
	 				}else if(message == "500"){
	 					layer.alert("系统繁忙！");
	 				}else{
	 					layer.alert(message);
	 				}
				}
		  });
	});
}

function editdepartment(id){

	layer_show('修改部门',path+'/department/department_toedit?id='+id,'400','300');
}

function add(){
	var zTree = parent.$.fn.zTree.getZTreeObj("treeDemo");
    var nodes = zTree.getSelectedNodes();
    var id=JSON.stringify(nodes[0].id);
	layer_show('添加部门',path+'/department/department_toadd?id='+id,'400','300');
}
function update(){

	var orgName =$("#name").val();
	if(orgName.length==0 || trim(orgName).length == 0){
		layer.alert("机构名称不能为空！");
		window.orgAdmin.document.getElementById("name").focus();
		return;
	}
	//验证只包含字母或者汉字
	var pattern =/(^[\u4e00-\u9fa5A-Za-z0-9_-]*$)/;
	//验证不能为纯数字
	var patternNum=/^\d+$/;
	if (!pattern.test(orgName)) {
		layer.alert("请输入合法的机构名称！");
		return false;
	}
	if (patternNum.test(orgName)) {
		layer.alert("机构名称不能为纯数字！");
		return false;
	}


    $("#form-resource").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "200"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
/*                         var index = parent.layer.getFrameIndex(window.name);
                        parent.query_brand_form.submit();
                        parent.layer.close(index); */
                        parent.parent.window.location.reload();
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        }
    });
}
function save(){

	var orgName =$("#name").val();
	if(orgName.length==0 || trim(orgName).length == 0){
		layer.alert("机构名称不能为空！");
		window.orgAdmin.document.getElementById("name").focus();
		return;
	}
	//验证只包含字母或者汉字
	var pattern =/(^[\u4e00-\u9fa5A-Za-z0-9_-]*$)/;
	//验证不能为纯数字
	var patternNum=/^\d+$/;
	if (!pattern.test(orgName)) {
		layer.alert("请输入合法的机构名称！");
		return false;
	}
	if (patternNum.test(orgName)) {
		layer.alert("机构名称不能为纯数字！");
		return false;
	}


    $("#form-resource").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "200"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
/*                         var index = parent.layer.getFrameIndex(window.name);
                        parent.query_brand_form.submit();
                        parent.layer.close(index); */
                        parent.parent.window.location.reload();
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        }
    });
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}